# coding=utf-8
import csv
from pathlib import Path
import os

class LimitCsvProcess():
    # @classmethod
    # def getLimitContent(cls,test_item,path = os.path.join(Path(__file__).parent.parent,"Assets/Limits.csv")):
    #     perLineDic = {}
    #     with open(path,encoding = "utf-8-sig",mode = "r") as f:
    #         dictReader = csv.DictReader(f)
    #         for row in dictReader:
    #             test_item = "{}_{}".format(row["TestName"],row["ParameterName"])
    #             assert (not bool(perLineDic.get(test_item))),"The test name {} is repeated.".format(test_item)
    #             perLineDic[test_item] = {"units":row["units"],"upperLimit":row["upperLimit"],"lowerLimit":
    #             row["lowerLimit"],"relaxedUpperLimit":row["relaxedUpperLimit"],"relaxedLowerLimit":row["relaxedLowerLimit"],
    #             "Condition":row["Condition"]}
    #     return perLineDic[test_item]
    @classmethod
    def getLimitContent(cls,path = os.path.join(Path(__file__).parent.parent,"Assets/Limits.csv")):
        perLineDic = {}
        with open(path,encoding = "utf-8-sig",mode = "r") as f:
            dictReader = csv.DictReader(f)
            for row in dictReader:
                test_item = "{}_{}".format(row["TestName"],row["ParameterName"])
                assert (not bool(perLineDic.get(test_item))),"The test name {} is repeated.".format(test_item)
                perLineDic[test_item] = {"units":row["units"],"upperLimit":row["upperLimit"],"lowerLimit":
                row["lowerLimit"],"relaxedUpperLimit":row["relaxedUpperLimit"],"relaxedLowerLimit":row["relaxedLowerLimit"],
                "Condition":row["Condition"]}
        return perLineDic[test_item]
if __name__ == "__main__":
    test_item = "Mogul_Left_Program_System_Zone7_Read_Mogul_Left_Program_Color_Read"
    # print(LimitCsvProcess.getLimitContent(test_item,path = os.path.join(Path(__file__).parent.parent,"Assets/Limits.csv")))
    print(LimitCsvProcess.getLimitContent(path = os.path.join(Path(__file__).parent.parent,"Assets/Limits.csv")))
